package controller;

import demo.pojo.User;
import demo.service.impl.TokenService;
import demo.service.impl.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import util.BaseResponse;

import javax.servlet.http.HttpServletRequest;

/**
 * @author caosinuo
 * @date 2019/5/22 10:09
 **/
@Controller
@RequestMapping("/user")
public class UserController {

   @Autowired
   private UserService userService;

   @Autowired
   private TokenService tokenService;

   @RequestMapping("/login")
   @ResponseBody
   public Object login(@RequestParam(value = "phoneNum") String username,@RequestParam(value = "captcha") String password,
                       HttpServletRequest request) {

      BaseResponse<User> responseMessage = new BaseResponse<>();
      responseMessage.setTime(System.currentTimeMillis());
      User user = this.userService.login(username, password);
      if (user == null) {
         responseMessage.setStatus(0);
         responseMessage.setMsg("用户不存在");
         return responseMessage;
      }
      return responseMessage;

   }

}
